package com.itbaizhan.listener;

import com.alibaba.fastjson.JSON;
import com.itbaizhan.domain.PayInfo;
import com.itbaizhan.service.AccountInfoService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author spf
 * @date 2024/4/23
 * @time 17:01
 */
@Component
@RocketMQMessageListener(consumerGroup = "consumer_notifymsg_group", topic = "notifymsg_topic")
public class NotifyMsgAccountListener implements RocketMQListener<String> {

    @Autowired
    private AccountInfoService accountInfoService;

    @Override
    public void onMessage(String message) {
        // 处理数据
        PayInfo payInfo = JSON.parseObject(message, PayInfo.class);

        // 操作账户
        if("success".equals(payInfo.getPayResult())){
            accountInfoService.updataAccount(payInfo);
        }
    }
}
